]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
iconGrid: Also consider left/right empty space as drop targets
authorJonas Dreßler <verdre@v0yd.nl>
Fri, 24 Jun 2022 11:50:42 +0000 (13:50 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 1 Feb 2023 12:56:28 +0000 (12:56 +0000)
Make it a bit easier to drag items to the start of pages by also taking
the left and right empty space into account, instead of considering it
an invalid target.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2348>

js/ui/iconGrid.js

index 313621a5e8c4a66605209fdf1792711d8e6c9b59..7030ed87cbd17519f91d0d61fa8ab0a3a98cceb3 100644 (file)
@@ -1021,9 +1021,6 @@ var IconGridLayout = GObject.registerClass({
         else
             adjY %= this._pageHeight;
 
-        if (adjX < leftEmptySpace || adjY < topEmptySpace)
-            return [0, 0, DragLocation.INVALID];
-
         const gridWidth =
             childSize * this.columnsPerPage +
             hSpacing * (this.columnsPerPage - 1);
@@ -1031,7 +1028,12 @@ var IconGridLayout = GObject.registerClass({
             childSize * this.rowsPerPage +
             vSpacing * (this.rowsPerPage - 1);
 
-        if (adjX > leftEmptySpace + gridWidth || adjY > topEmptySpace + gridHeight)
+        const inTopEmptySpace = adjY < topEmptySpace;
+        const inLeftEmptySpace = adjX < leftEmptySpace;
+        const inRightEmptySpace = adjX > leftEmptySpace + gridWidth;
+        const inBottomEmptySpace = adjY > topEmptySpace + gridHeight;
+
+        if (inTopEmptySpace || inBottomEmptySpace)
             return [0, 0, DragLocation.INVALID];
 
         const halfHSpacing = hSpacing / 2;
@@ -1042,12 +1044,23 @@ var IconGridLayout = GObject.registerClass({
             const item = visibleItems[i];
             const childBox = item.allocation;
 
-            // Outside the icon boundaries
-            if (x < childBox.x1 - halfHSpacing ||
-                x > childBox.x2 + halfHSpacing ||
-                y < childBox.y1 - halfVSpacing ||
-                y > childBox.y2 + halfVSpacing)
-                continue;
+            const firstInRow = i % this.columnsPerPage === 0;
+            const lastInRow = i % this.columnsPerPage === this.columnsPerPage - 1;
+
+            // Check icon boundaries
+            if ((inLeftEmptySpace && firstInRow) ||
+                (inRightEmptySpace && lastInRow)) {
+                if (y < childBox.y1 - halfVSpacing ||
+                    y > childBox.y2 + halfVSpacing)
+                    continue;
+            } else {
+                // eslint-disable-next-line no-lonely-if
+                if (x < childBox.x1 - halfHSpacing ||
+                    x > childBox.x2 + halfHSpacing ||
+                    y < childBox.y1 - halfVSpacing ||
+                    y > childBox.y2 + halfVSpacing)
+                    continue;
+            }
 
             let dragLocation;